package Qverst::CSS::Optimize::List;
use Moose::Role;

use Carp;
use CSS::Builder::Element::Simple;

requires 'simple';

sub optimize_list {
      my ($self , $property_list , $mode) = @_;
      
      my @can = qw(style-image style-position style-type);
      my $list = $property_list->style;
      
      if ($list) {
            
            if ($list->inherit) {
                  
            } else {
                  
                  
                  
            }
            
      } else {
            
            my @val = ();
            my $new_list = CSS::Builder::Element::Simple->new();
            
            foreach my $prop (@can) {
                  my $value = $property_list->$prop;
                  if ($value) {
                        push @val , $value->value;
                        if ($value->important) {
                              $new_list->important(1);
                              last;
                        }
                  } else {
                        push @val , "";
                  }
            }
            
            # check if it's inherit
            my $inh = 0;
            foreach my $prop (@can) {
                  my $value = $property_list->$prop;
                  if ($value) {
                        if ($value->inherit) {
                              $inh++;
                        }
                  }
            }
            
            if ($inh eq 3) {
                  $new_list->inherit(1);
            } elsif ($inh eq 0) {
                  $new_list->value(join " " , @val);
            }
            
            if ($new_list->inherit or $new_list->value) {
                  $property_list->style($new_list);
                  foreach my $prop (@can) {
                        $property_list->$prop('');
                  }
            }
            
      }
}

1;
